home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / spriteWizard.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  46.5 KB  |  1,915 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. includeEffectsGlobals();
  18.  
  19. global string $gSpriteWizardParticle;
  20.  
  21. proc int swFrameRange()
  22. //
  23. //    Description:
  24. //        Return the selected image frame range
  25. //
  26. {
  27.     int $startFrame = `intFieldGrp -q -value1 swFileRangeInt`;
  28.     int $endFrame = `intFieldGrp -q -value2 swFileRangeInt`;
  29.     return ($endFrame-$startFrame);
  30. }
  31.  
  32. proc int newImageFileName(string $imageFile)
  33. //
  34. //    Description:
  35. //        Return whether the file name is new or not
  36. //
  37. {
  38.     global string $gSpriteWizardParticle;
  39.     string $fileTexture = particleSpriteFileTexture( $gSpriteWizardParticle );
  40.     if ("" != $fileTexture) {
  41.         string $file = `getAttr ($fileTexture+".fileTextureName")`;
  42.         return ($file != $imageFile);
  43.     }
  44.     return 0;
  45. }
  46.  
  47. proc int existingSpriteAnimation()
  48. //
  49. //    Description:
  50. //        Return the current sprite animation attribute value
  51. //
  52. {
  53.     global string $gSpriteWizardParticle;
  54.     if("" != $gSpriteWizardParticle &&
  55.        `attributeQuery -exists -node $gSpriteWizardParticle SpriteAnimation` ) {
  56.         int $animVal = `getAttr ($gSpriteWizardParticle+".SpriteAnimation")`;
  57.         return $animVal;
  58.     }
  59.     return 0;
  60. }
  61.  
  62. proc createHelpButtons(string $parent)
  63. // 
  64. //    Description:
  65. //        Create buttons (one for each frame) that also switch between
  66. //        the tabs.
  67. //
  68. //    Arguments:
  69. //        The parent argument is assumed to be a formLayout.
  70. //
  71. {
  72.     setParent $parent;
  73.  
  74.     string $frame1 = `button -label "Close"
  75.                                     -ann "Close this window"
  76.                                     -command "deleteUI WizardHelpWindow"`;
  77.  
  78.     string $frame2 = `button -label "Read Manual" 
  79.                     -ann "Open web window to the manual to sprites"
  80.                     -command ("//showHelp")`;  // Marker needs to be added
  81.  
  82.     formLayout -edit
  83.         -attachForm     $frame1 "top"    5
  84.         -attachForm     $frame1 "left"   5
  85.         -attachForm     $frame1 "bottom" 5
  86.         -attachPosition $frame1 "right"  2 50
  87.  
  88.         -attachForm     $frame2 "top"    5
  89.         -attachPosition $frame2 "left"   2 50
  90.         -attachPosition $frame2 "right"  2 100
  91.         -attachForm     $frame2 "bottom" 5
  92.  
  93.         $parent;
  94. }
  95.  
  96. proc wizardHelpWindow(string $helpTitle, string $helpText[])
  97. {
  98.     //    If the window already exists then just show it and return.
  99.     //
  100.     if (`window -exists WizardHelpWindow`) {
  101.         deleteUI -window WizardHelpWindow;
  102.     }
  103.  
  104.     //    Otherwise, build the window.
  105.     //
  106.     window -title ("Sprite Wizard Help")
  107.         -iconName "Sprite Wizard"
  108.         -width    500
  109.         -height   200
  110.         -sizeable true
  111.         WizardHelpWindow;
  112.  
  113.     string $form = `formLayout SpriteWizardForm`;
  114.  
  115.     string $textArea = `columnLayout`;
  116.  
  117.     text -align "center" -l $helpTitle;
  118.     separator -w 200 -h 5 -style "in";
  119.     string $txt;
  120.     for ($txt in $helpText) {
  121.         text -l $txt;
  122.     }
  123.     setParent ..;
  124.  
  125.     string $buttons = `formLayout`;
  126.     setParent ..;
  127.  
  128.     createHelpButtons($buttons);
  129.     
  130.     formLayout -edit
  131.         -attachForm    $textArea    "top"    0
  132.         -attachForm    $textArea    "left"   0
  133.         -attachControl $textArea    "bottom" 0 $buttons
  134.         -attachForm    $textArea    "right"  0
  135.  
  136.         -attachNone    $buttons "top"
  137.         -attachForm    $buttons "left"   0
  138.         -attachForm    $buttons "bottom" 0
  139.         -attachForm    $buttons "right"  0
  140.         $form;
  141.  
  142.     showWindow WizardHelpWindow; 
  143. }
  144.  
  145. proc string[] selectedParticleObjects()
  146. //
  147. // Description:
  148. //   Return the list of selected particle objects.
  149. {
  150.     string $selList[] = `ls -sl`;
  151.     int $particleCount;
  152.     string $list[];
  153.  
  154.     int $i;
  155.     for ($i = size($selList)-1; $i >= 0; $i--)
  156.     {
  157.         if (`particleExists $selList[$i]`)
  158.         {
  159.             $list[ $particleCount ] = $selList[$i];
  160.             $particleCount++;
  161.         }
  162.     }
  163.     return $list;
  164. }
  165.  
  166. global proc int particleIsSelected()
  167. //
  168. // Description:
  169. //   Return true if some particle object is selected, false otherwise.
  170. {
  171.     string $selList[] = selectedParticleObjects();
  172.     return (size($selList) > 0);
  173. }
  174.  
  175. global proc spriteWizard( string $object, string $image )
  176. // 
  177. // Description:
  178. //   Determine the exact sequence of images to be used (sorting out issues of
  179. // suffixes and suff formatting), then launch the main wizard window.
  180. {
  181.     // Get the particle shape.
  182.     //
  183.     string $shape = getShapeFromObject( $object, 0, 0 );
  184.  
  185.     // Build and launch the wizard window
  186.     //
  187.     wizardWindow( $shape, $image );
  188. }
  189.  
  190. global proc spriteWizardVisor( string $image )
  191. //
  192. // Description:
  193. //   This is the front end to invoke the wizard from Visor.
  194. // Currently it just passes the file name to the main wizard.
  195.     // Get list of selected particle objects.
  196.     //
  197.     string $objects[] = selectedParticleObjects();    
  198.     if (size($objects) == 0)
  199.     {
  200.         error("Please choose a particle object to which to apply sprites");
  201.         return;
  202.     }
  203.     else
  204.     if (size($objects) > 1)
  205.     {
  206.         error("Please choose just one particle object");
  207.         return;
  208.     }
  209.  
  210.     spriteWizard( $objects[0], $image );
  211. }
  212.  
  213.  
  214. global proc spriteWizardMenu()
  215. //
  216. // Description:
  217. //   This is the front end for the wizard from the Particles menu.
  218. // It invokes a file dialog to get an image name, and passes
  219. // that to the main wizard.
  220. //
  221. {
  222.     // We need a unique selected particle object to proceed.
  223.     //
  224.     string $objects[] = selectedParticleObjects();
  225.     
  226.     if (size($objects) == 0)
  227.     {
  228.         error("Please choose a particle object to which to apply sprites");
  229.         return;
  230.     }
  231.     else
  232.     if (size($objects) > 1)
  233.     {
  234.         error("Please choose just one particle object");
  235.         return;
  236.     }
  237.  
  238.     spriteWizard( $objects[0], "" );
  239. }
  240.  
  241. proc doApplySprites()
  242. //
  243. //  Description:
  244. //  This is the routine which finishes the wizard's action by actually applying the sprites.
  245. //  It reads the input values from the controls and calls the applySpriteWizard script
  246. //  to make the nodes and generate the expressions.
  247. {
  248.  
  249.     // User has hit "apply."  Apply the sprites, we're done.
  250.     //
  251.     int $startFrame = `intFieldGrp -q -value1 swFileRangeInt`;
  252.     int $endFrame = `intFieldGrp -q -value2 swFileRangeInt`;
  253.     string $shape = `textField -q -text swGlobalParticleShape`;
  254.     string $image = `textFieldButtonGrp -q -fileName swFileSelectionGroup`;
  255.  
  256.     int $animation = 0; 
  257.     int $selection = 0;
  258.     int $cycle = 0;
  259.     float $cycleLength = 100;
  260.     int $invert  = 0;
  261.  
  262.     //
  263.     // Get the animation option.
  264.     //
  265.     string $animationOption = `radioCollection -q -select
  266.         swAnimationOptionCollection`;
  267.     if( $animationOption == "swSingleImageButton" )
  268.     {
  269.         $animation = 0;
  270.     }
  271.     else if( $animationOption == "swCycleButton" )
  272.     {
  273.         $animation = 1;
  274.     }
  275.     else
  276.     {
  277.         $animation = existingSpriteAnimation();
  278.     }
  279.  
  280.     //
  281.     // Get the image selection option.
  282.     //
  283.     string $imageSelectionOption = `radioCollection -q -select
  284.         swImageSelectionOptionCollection`;
  285.     if( $imageSelectionOption == "swFirstImageButton" )
  286.     {
  287.         $selection = 0;
  288.     }
  289.     else if( $imageSelectionOption == "swParticleIdButton" )
  290.     {
  291.         $selection = 1;
  292.     }
  293.     else if( $imageSelectionOption == "swRandomButton" )
  294.     {
  295.         $selection = 2;
  296.     }
  297.     else if( $imageSelectionOption == "swSpriteNumPPButton" )
  298.     {
  299.         $selection = 3;
  300.     }
  301.     else if( $imageSelectionOption == "swInitRampButton" )
  302.     {
  303.         $selection = 4;
  304.     }
  305.     else
  306.     {
  307.         warning("Invalid image selection option selected.");
  308.     }
  309.  
  310.     //
  311.     // Get the cycle option.
  312.     //
  313.     string $cycleOption = `radioCollection -q -select
  314.         swCycleOptionCollection`;
  315.     if( $cycleOption == "swLinearUpButton" )
  316.     {
  317.         $cycle = 0;
  318.     }
  319.     else if( $cycleOption == "swSmoothUpButton" )
  320.     {
  321.         $cycle = 1;
  322.     }
  323.     else if( $cycleOption == "swLinearUpDownButton" )
  324.     {
  325.         $cycle = 2;
  326.     }
  327.     else if( $cycleOption == "swSmoothUpDownButton" )
  328.     {
  329.         $cycle = 3;
  330.     }
  331.     else if ( $cycleOption == "swSpriteCustomButton" )
  332.     {
  333.         $cycle = 4;
  334.     }
  335.     else if ( $cycleOption == "swRampButton" )
  336.     {
  337.         $cycle = 5;
  338.     }
  339.  
  340.     //
  341.     // Get cycle length.
  342.     //
  343.     if( `checkBox -q -value swCycleOnceCheckbox` )
  344.     {
  345.         $cycleLength = 0;
  346.     }
  347.     else
  348.     {
  349.         $cycleLength = `floatSliderGrp -q -value swCycleLengthValue`;
  350.     }
  351.  
  352.     //
  353.     // Get the invert value.
  354.     //
  355.     if( $animation == 0 )
  356.     {
  357.         if( `radioCollection -q -select
  358.             swCycleOptionCollection` == "swRampButton" )
  359.         {
  360.             $invert = `checkBox -q -value swInvertRampCheckbox`;
  361.         }
  362.     }
  363.     else
  364.     {
  365.         if( `radioCollection -q -select
  366.             swCycleOptionCollection` == "swRampButton" )
  367.         {
  368.             $invert = `checkBox -q -value swInvertRampCheckbox`;
  369.         }
  370.         else
  371.         {
  372.             $invert = `checkBox -q -value swInvertCycleCheckbox`;
  373.         }
  374.     }
  375.  
  376.     // Invoke applySpriteWizard to build the sprites.
  377.     //
  378.     applySpriteWizard( $shape, $image, $startFrame, $endFrame,
  379.         $animation, $selection, $cycle, $cycleLength, $invert  );
  380.         
  381.     // Take down the sprite wizard window
  382.     //
  383.     deleteUI -window WizardExampleWindow;
  384. }
  385.  
  386. global proc wizardExampleWindowSelectFileSelection()
  387. {
  388.     textField -e -text "file" swGlobalCurrentFrame;
  389.     tabLayout -edit
  390.         -selectTab swFileSelectionLayout WizardExampleWindowTabs;
  391.  
  392.     string $selectedFile =
  393.         `textFieldButtonGrp -q -fileName swFileSelectionGroup`;
  394.  
  395.     if( ( $selectedFile == "" ) ||
  396.         ( `filetest -r $selectedFile` == 0 ) )
  397.     {
  398.         button -e -enable false applyContinueButton;
  399.     }
  400.     else
  401.     {
  402.         button -e -enable true applyContinueButton;
  403.     }
  404.  
  405.     button -e -label "Continue" applyContinueButton;
  406.     button -e -enable false backButton;
  407. }
  408.  
  409. global proc wizardExampleWindowSelectAnimation()
  410. // 
  411. //      Description:
  412. //              Invoked when Frame 1 button is selected.
  413. //
  414. //              Make Frame 1 active.
  415. //
  416. {
  417.     textField -e -text "animation" swGlobalCurrentFrame;
  418.     tabLayout -edit
  419.         -selectTab swAnimationOptionsLayout WizardExampleWindowTabs;
  420.  
  421.     updateAnimationApplyButton();
  422.     button -e -enable true backButton;
  423. }
  424.  
  425. global proc wizardExampleWindowSelectImageSelection()
  426. // 
  427. //      Description:
  428. //              Invoked when Frame 2 button is selected.
  429. //
  430. //              Make Frame 2 active.
  431. //
  432. {
  433.     textField -e -text "imageSelection" swGlobalCurrentFrame;
  434.     tabLayout -edit
  435.         -selectTab swImageSelectionLayout WizardExampleWindowTabs;
  436.  
  437.     button -e -label "Continue" applyContinueButton;
  438.     button -e -enable true backButton;
  439. }
  440.  
  441. global proc wizardExampleWindowSelectCycle()
  442. // 
  443. //      Description:
  444. //              Invoked when Frame 3 button is selected.
  445. //
  446. //              Make Frame 3 active.
  447. //
  448. {
  449.     textField -e -text "cycle" swGlobalCurrentFrame;
  450.     tabLayout -edit
  451.         -selectTab swCycleOptionsLayout WizardExampleWindowTabs;
  452.  
  453.     button -e -label "Continue" applyContinueButton;
  454.     button -e -enable true backButton;
  455. }
  456.  
  457. global proc wizardExampleWindowSelectSummary()
  458. // 
  459. //      Description:
  460. //              Invoked when Frame 3 button is selected.
  461. //
  462. //              Make Frame 3 active.
  463. //
  464. {
  465.     //
  466.     // Generate the summary string.
  467.     //
  468.     int $startFrame = `intFieldGrp -q -value1 swFileRangeInt`;
  469.     int $endFrame = `intFieldGrp -q -value2 swFileRangeInt`;
  470.     string $shape = `textField -q -text swGlobalParticleShape`;
  471.     string $image = `textFieldButtonGrp -q -fileName swFileSelectionGroup`;
  472.  
  473.     int $animation = 0; 
  474.     int $selection = 0;
  475.     int $cycle = 0;
  476.     float $cycleLength = 100;
  477.     int $invert  = 0;
  478.  
  479.     //
  480.     // Get the animation option.
  481.     //
  482.     string $animationOption = `radioCollection -q -select
  483.         swAnimationOptionCollection`;
  484.     if( $animationOption == "swSingleImageButton" )
  485.     {
  486.         $animation = 0;
  487.     }
  488.     else if( $animationOption == "swCycleButton" )
  489.     {
  490.         $animation = 1;
  491.     }
  492.     else
  493.     {
  494.         warning("Invalid sprite animation option selected.");
  495.     }
  496.  
  497.     //
  498.     // Get the image selection option.
  499.     //
  500.     string $imageSelectionOption = `radioCollection -q -select
  501.         swImageSelectionOptionCollection`;
  502.     if( $imageSelectionOption == "swFirstImageButton" )
  503.     {
  504.         $selection = 0;
  505.     }
  506.     else if( $imageSelectionOption == "swParticleIdButton" )
  507.     {
  508.         $selection = 1;
  509.     }
  510.     else if( $imageSelectionOption == "swRandomButton" )
  511.     {
  512.         $selection = 2;
  513.     }
  514.     else if( $imageSelectionOption == "swSpriteNumPPButton" )
  515.     {
  516.         $selection = 3;
  517.     }
  518.     else if( $imageSelectionOption == "swInitRampButton" )
  519.     {
  520.         $selection = 4;
  521.     }
  522.     else
  523.     {
  524.         warning("Invalid image selection option selected.");
  525.     }
  526.  
  527.     //
  528.     // Get the cycle option.
  529.     //
  530.     string $cycleOption = `radioCollection -q -select
  531.         swCycleOptionCollection`;
  532.     if( $cycleOption == "swLinearUpButton" )
  533.     {
  534.         $cycle = 0;
  535.     }
  536.     else if( $cycleOption == "swSmoothUpButton" )
  537.     {
  538.         $cycle = 1;
  539.     }
  540.     else if( $cycleOption == "swLinearUpDownButton" )
  541.     {
  542.         $cycle = 2;
  543.     }
  544.     else if( $cycleOption == "swSmoothUpDownButton" )
  545.     {
  546.         $cycle = 3;
  547.     }
  548.     else if( $cycleOption == "swSpriteCustomButton" )
  549.     {
  550.         $cycle = 4;
  551.     }
  552.     else if( $cycleOption == "swRampButton" )
  553.     {
  554.         $cycle = 5;
  555.     }
  556.  
  557.     //
  558.     // Get cycle length.
  559.     //
  560.     if( `checkBox -q -value swCycleOnceCheckbox` )
  561.     {
  562.         $cycleLength = 0;
  563.     }
  564.     else
  565.     {
  566.         $cycleLength = `floatSliderGrp -q -value swCycleLengthValue`;
  567.     }
  568.  
  569.     //
  570.     // Get the invert value.
  571.     //
  572.     if( $animation == 0 )
  573.     {
  574.         if( `radioCollection -q -select
  575.             swImageSelectionOptionCollection` == "swRampButton" )
  576.         {
  577.             $invert = `checkBox -q -value swInvertRampCheckbox`;
  578.         }
  579.     }
  580.     else
  581.     {
  582.         if( `radioCollection -q -select
  583.             swImageSelectionOptionCollection` == "swRampButton" )
  584.         {
  585.             $invert = `checkBox -q -value swInvertRampCheckbox`;
  586.         }
  587.         else
  588.         {
  589.             $invert = `checkBox -q -value swInvertCycleCheckbox`;
  590.         }
  591.     }
  592.  
  593.     string $summary = "";
  594.     $summary += "Particle object: "+$shape+"\n";
  595.     $summary += "Sprite Image:\n";
  596.     $summary += "    "+$image+"\n";
  597.     $summary += "    Frames: " +$startFrame+" - "+$endFrame+"\n";
  598.     if( $animation == 0 )
  599.     {
  600.         $summary += "No Animation:\n";
  601.         switch( $selection )
  602.         {
  603.             case 0:
  604.                 $summary += "    All particles use the first image in the sequence\n";
  605.                 break;
  606.             case 1:
  607.                 $summary += "    Each particle uses its \"particleId\" value to choose its image\n";
  608.                 break;
  609.             case 2:
  610.                 $summary += "    Each particle chooses a random image\n";
  611.                 break;
  612.             case 3:
  613.                 $summary += "    Each particle uses its \"spriteNumPP\" value to choose its image\n";
  614.                 break;
  615.             case 4:
  616.                 if( $invert == 0 )
  617.                 {
  618.                     $summary += "    Each particle uses the ramp to choose its image\n";
  619.                 }
  620.                 else
  621.                 {
  622.                     $summary += "    Each particle uses the inverse of the ramp to choose its image\n";
  623.                 }
  624.                 break;
  625.         }
  626.     }
  627.     else
  628.     {
  629.         string $up = "up";
  630.         string $down = "down";
  631.         $summary += "Cycle Images:\n";
  632.         switch( $selection )
  633.         {
  634.             case 0:
  635.                 $summary += "    All particles use the first image in the sequence as their first image.\n";
  636.                 break;
  637.             case 1:
  638.                 $summary += "    Each particle uses its \"particleId\" value to choose its first image.\n";
  639.                 break;
  640.             case 2:
  641.                 $summary += "    Each particle chooses a random first image.\n";
  642.                 break;
  643.             case 3:
  644.                 $summary += "    Each particle uses its \"spriteNumPP\" value to choose its first image.\n";
  645.                 break;
  646.             case 4:
  647.                 $summary += "    Each particle uses the ramp connected to \"spriteNumRamp\" to choose its images.\n";
  648.                 break;
  649.         }
  650.         if( $invert == 1 )
  651.         {
  652.             $up = "down";
  653.             $down = "up";
  654.         }
  655.         switch( $cycle )
  656.         {
  657.             case 0:
  658.                 $summary += "    The images will cycle "+$up+" linearly ";
  659.                 break;
  660.             case 1:
  661.                 $summary += "    The images will ease-in/ease-out "+$up+" ";
  662.                 break;
  663.             case 2:
  664.                 $summary += "    The images will cycle "+$up+" and then "+$down+" linearly ";
  665.                 break;
  666.             case 3:
  667.                 $summary += "    The images will ease-in/ease-out "+$up+" and then "+$down+" ";
  668.             case 4:
  669.                 $summary += "    The images will animated based on the \"spriteNumPP\" value";
  670.             case 5:
  671.                 $summary += "    A ramp will control the image cycling ";
  672.                 break;
  673.         }
  674.         if( $cycleLength == 0 )
  675.         {
  676.             $summary += "once over the lifespan.";
  677.         }
  678.         else
  679.         {
  680.             $summary += "every "+$cycleLength+" frames.";
  681.         }
  682.     }
  683.  
  684.     scrollField -e -text $summary swSummaryField;
  685.  
  686.     //
  687.     // Display the summary frame.
  688.     //
  689.     textField -e -text "summary" swGlobalCurrentFrame;
  690.     tabLayout -edit
  691.         -selectTab swSummaryLayout WizardExampleWindowTabs;
  692.  
  693.     button -e -label "Apply" applyContinueButton;
  694.     button -e -enable true backButton;
  695. }
  696.  
  697. global proc swApplyContinueCallback()
  698. //
  699. //  Description: 
  700. //    This is the callback for when the the "apply"/"continue" button
  701. //    in the sprite wizard is pushed.
  702. {
  703.     string $currentFrame = `textField -q -text swGlobalCurrentFrame`;
  704.     if ( $currentFrame == "file" ) {
  705.         int $frameRange = swFrameRange();
  706.         if ($frameRange == 0) {
  707.             wizardExampleWindowSelectSummary();            
  708.         } else {
  709.             wizardExampleWindowSelectAnimation();
  710.         }
  711.     }
  712.     else if ( $currentFrame == "animation" ) {
  713.         if (`radioButton -q -sl swSameSetupButton`) {
  714.             doApplySprites();
  715.         } else {
  716.             wizardExampleWindowSelectImageSelection();
  717.         }
  718.     }
  719.     else if ( $currentFrame == "imageSelection" ) {
  720.         if (`radioButton -q -sl swCycleButton`) {
  721.             wizardExampleWindowSelectCycle();
  722.         } else {
  723.             wizardExampleWindowSelectSummary();
  724.         }
  725.     }
  726.     else if ( $currentFrame == "cycle" ) {
  727.         wizardExampleWindowSelectSummary();
  728.     }
  729.     else if ( $currentFrame == "summary" ) {
  730.         doApplySprites();
  731.     }            
  732. }
  733.  
  734. global proc swBackCallback()
  735. //
  736. //  Description: 
  737. //    This is the callback for the "back" button in the sprite wizard. 
  738. {
  739.     string $currentFrame = `textField -q -text swGlobalCurrentFrame`;
  740.     if( $currentFrame == "file" )
  741.     {
  742.         //
  743.         // This should never happen, but if it does,
  744.         // reset the animation frame.
  745.         //
  746.         wizardExampleWindowSelectFileSelection();
  747.     }
  748.     else if( $currentFrame == "animation" )
  749.     {
  750.         wizardExampleWindowSelectFileSelection();
  751.     }
  752.     else if( $currentFrame == "imageSelection" )
  753.     {
  754.         wizardExampleWindowSelectAnimation();
  755.     }
  756.     else if( $currentFrame == "cycle" )
  757.     {
  758.         wizardExampleWindowSelectImageSelection();
  759.     }
  760.     else if( $currentFrame == "summary" )
  761.     {
  762.         int $frameRange = swFrameRange();
  763.         if (0 == $frameRange) {
  764.             wizardExampleWindowSelectFileSelection();
  765.         } else {
  766.             if (`radioButton -q -sl swCycleButton`) {
  767.                 wizardExampleWindowSelectCycle();
  768.             } else {        
  769.                 wizardExampleWindowSelectImageSelection();
  770.             }
  771.         }
  772.     }
  773. }
  774.  
  775. global proc swCloseCallback()
  776. //
  777. //  Description: 
  778. //    This is the callback for the "close" button in the sprite wizard. 
  779. {
  780.     deleteUI -window WizardExampleWindow;
  781.     if (`window -exists WizardHelpWindow`) {
  782.         deleteUI -window WizardHelpWindow;
  783.     }
  784. }
  785.  
  786. global proc resetSpriteSettings()
  787. //
  788. //  Description:  
  789. //    This is the callback for the "reset settings" button.
  790. //    Resets settings depending on the screen the user is on.
  791. //
  792. {
  793.     string $currentFrame = `textField -q -text swGlobalCurrentFrame`;
  794.  
  795.     if ($currentFrame == "file") {
  796.         textFieldButtonGrp -e -fileName "" swFileSelectionGroup;
  797.         updateSelectedFileInfo();
  798.     } else if ($currentFrame == "animation") {
  799.         radioButton -e -sl swSingleImageButton;
  800.     } else if ($currentFrame == "imageSelection") {
  801.         radioButton -e -sl swFirstImageButton;
  802.         checkBox -e -enable false swInvertRampCheckbox;
  803.         checkBox -e -value false swInvertRampCheckbox;        
  804.     } else if( $currentFrame == "cycle" ) {
  805.         radioButton -e -sl swLinearUpButton;
  806.         checkBox -e -value true swCycleOnceCheckBox;
  807.         floatSliderGrp -e -value 100.0c swCycleLengthValue;
  808.         floatSliderGrp -e -enable false swCycleLengthValue;
  809.         checkBox -e -value false swInvertCycleCheckBox;
  810.     }
  811. }
  812.  
  813.  
  814. global proc swMoreHelpCallback()
  815. //
  816. //  Description:  
  817. //    This is the callback for the "help" button.  Display help appropriate
  818. //  to the screen the user is on.
  819. {
  820.     string $currentFrame = `textField -q -text swGlobalCurrentFrame`;
  821.     string $result;
  822.  
  823.     if ($currentFrame == "file") {
  824.         wizardHelpWindow("Sprite File Selection:",
  825.             {"Use the Browse button to select an image file. To use a sequence of image files, the image",
  826.              "file name should be of the form name.number.fmt, for example: myImage.0007.iff. Any image",
  827.              "in the sequence will do. Maya will be able to find the range of sequential images using",
  828.              "the file names."});
  829.     }
  830.     else if ($currentFrame == "animation") {
  831.         wizardHelpWindow("Sprite Animation:",
  832.             {"Choose whether as the animation plays, the sprites display a fixed image or a sequence",
  833.                  "of images."});
  834.     } else if ($currentFrame == "imageSelection") {
  835.         wizardHelpWindow("Sprite Images:",
  836.             {"Choose which image is used for each particle."});
  837.     } else if( $currentFrame == "cycle" ) {
  838.         wizardHelpWindow("Sprite Cycling:",
  839.             {"Choose how each sprite cycles the images."});
  840.     }
  841.     else if( $currentFrame == "summary" ) {
  842.         wizardHelpWindow("Summary Help:",
  843.             {"The sprite wizard summary window shows you the options you have selected for your sprite.",
  844.                  "If you are happy with the options listed, click `Apply`. If you want to modify",
  845.                  "the options, click `Back` to edit the desired options."});
  846.     }
  847. }
  848.  
  849. global proc updateAnimationApplyButton()
  850. {
  851.     int $sameSetup = `radioButton -q -select swSameSetupButton`;
  852.     if( $sameSetup == 1 )
  853.     {
  854.         button -e -label "Apply" applyContinueButton;
  855.     }
  856.     else
  857.     {
  858.         button -e -label "Continue" applyContinueButton;
  859.     }
  860. }
  861.  
  862. proc createGlobalsFrame(string $parent)
  863. //
  864. // This frame is used strictly to hold global
  865. // variable values.  It is never actually displayed.
  866. //
  867. {
  868.     setParent $parent;
  869.  
  870.     columnLayout swGlobalsLayout;
  871.     textField
  872.         -text $parent
  873.         -editable false
  874.         swGlobalParent;
  875.     textField
  876.         -text ""
  877.         -editable false
  878.         swGlobalImageName;
  879.     textField
  880.         -text ""
  881.         -editable false
  882.         swGlobalParticleShape;
  883.     intField
  884.         -value 0
  885.         -editable false
  886.         swGlobalSingleFrame;
  887.     intField
  888.         -value 0
  889.         -editable false
  890.         swGlobalStartFrame;
  891.     intField
  892.         -value 0
  893.         -editable false
  894.         swGlobalEndFrame;
  895.  
  896.     textField
  897.         -text ""
  898.         -editable false
  899.         swGlobalCurrentFrame;
  900. }
  901.  
  902. global proc getSpriteBaseFile()
  903. {
  904.     string $dirMask = `workspace -q -rd`;
  905.     string $sourceImg = `workspace -rte sourceImages`;
  906.     if (size($sourceImg) > 0) {
  907.         $dirMask += $sourceImg;
  908.     } else {
  909.         $sourceImg = `workspace -fre sourceImages`;
  910.         if (size($sourceImg) > 0) {
  911.             $dirMask += $sourceImg;
  912.         } else if (`file -q -ex ($dirMask+"sourceimages")`) {
  913.             $dirMask += "sourceImages";
  914.         }
  915.     }
  916.     $dirMask += ("/*");
  917.     string $spriteFile = `fileDialog -dm $dirMask`;
  918.     textFieldButtonGrp -e -fileName $spriteFile swFileSelectionGroup;
  919.     updateSelectedFileInfo();
  920. }
  921.  
  922.  
  923. global proc updateSelectedFileInfo()
  924. {
  925.     string $selectedFile =
  926.         `textFieldButtonGrp -q -fileName swFileSelectionGroup`;
  927.  
  928.     int $badFileName = 0;
  929.  
  930.     if( ( $selectedFile == "" ) ||
  931.         ( `filetest -r $selectedFile` == 0 ) )
  932.     {
  933.         if( `button -exists applyContinueButton` )
  934.         {
  935.             button -e -enable false applyContinueButton;
  936.         }
  937.  
  938.         if( $selectedFile != "" )
  939.         {
  940.             $badFileName = 1;
  941.         }
  942.  
  943.         $selectedFile = "";
  944.     }
  945.     else
  946.     {
  947.         if( `button -exists applyContinueButton` )
  948.         {
  949.             button -e -enable true applyContinueButton;
  950.         }
  951.     }
  952.  
  953.     string $fileInfo[];
  954.     if ($selectedFile != "") {
  955.         $fileInfo = getConnectedFrameRange( $selectedFile );
  956.     }
  957.  
  958.     string $parent = `textField -q -text swGlobalParent`;
  959.     string $range = ($parent+"|swFileSelectionLayout|swFileRangeLayout|swFileRangeInt|");
  960.  
  961.     int $currentMin1 = `intField -q -min ($range+"field1")`;
  962.     int $currentMin2 = `intField -q -min ($range+"field2")`;
  963.     intFieldGrp -e -value1 (max(0,$currentMin1)) swFileRangeInt;
  964.     intFieldGrp -e -value2 (max(0,$currentMin2)) swFileRangeInt;
  965.     intField -e -min 0 ($range+"field1");
  966.     intField -e -min 0 ($range+"field2");
  967.     intField -e -max 99999 ($range+"field1");
  968.     intField -e -max 99999 ($range+"field2");
  969.     intFieldGrp -e -value1 0 swFileRangeInt;
  970.     intFieldGrp -e -value2 0 swFileRangeInt;
  971.  
  972.     int $infoSize = size( $fileInfo );
  973.     if( $infoSize == 0 )
  974.     {
  975.         //
  976.         // There is no selected file. Go to the defaults.
  977.         //
  978.         textFieldGrp -e -text "" swSelectedFileText;
  979.         intFieldGrp -e -enable false swFileRangeInt;
  980.         columnLayout -e -visible false swFileRangeLayout;
  981.         intField -e -value 1 swGlobalSingleFrame;
  982.     }
  983.     else if( $infoSize == 2 )
  984.     {
  985.         //
  986.         // The selected file was not numbered.
  987.         // This is not an error.
  988.         //
  989.         textFieldGrp -e -text $fileInfo[1] swSelectedFileText;
  990.         intFieldGrp -e -enable false swFileRangeInt;
  991.         columnLayout -e -visible false swFileRangeLayout;
  992.         intField -e -value 1 swGlobalSingleFrame;
  993.     }
  994.     else if( $infoSize == 4 )
  995.     {
  996.         //
  997.         // The file is numbered.
  998.         //
  999.         textFieldGrp -e -text $fileInfo[1] swSelectedFileText;
  1000.         int $firstFile = $fileInfo[2];
  1001.         int $lastFile = $fileInfo[3];
  1002.  
  1003.         intFieldGrp -e -value1 $firstFile swFileRangeInt;
  1004.         intFieldGrp -e -value2 $lastFile swFileRangeInt;
  1005.  
  1006.         intField -e -step 1 ($range+"field1");
  1007.         intField -e -step 1 ($range+"field2");
  1008.         intField -e -min $firstFile ($range+"field1");
  1009.         intField -e -min $firstFile ($range+"field2");
  1010.         intField -e -max $lastFile ($range+"field1");
  1011.         intField -e -max $lastFile ($range+"field2");
  1012.         intFieldGrp -e -enable true swFileRangeInt;
  1013.         intFieldGrp -e -label ("Min: "+$firstFile) swFileRangeInt;
  1014.         intFieldGrp -e -annotation "Index of first and last file to use." -extraLabel ($lastFile+" :Max") swFileRangeInt;
  1015.         columnLayout -e -visible true swFileRangeLayout;
  1016.         intField -e -value 0 swGlobalSingleFrame;
  1017.     }
  1018.  
  1019.     if( $badFileName == 1)
  1020.     {
  1021.         textFieldGrp -e
  1022.             -text "Bad File Name!"
  1023.             swSelectedFileText;
  1024.     } else {
  1025.         int $newFileName = newImageFileName($selectedFile);
  1026.         if (`radioButton -ex swSameSetupButton`) {
  1027.             radioButton -e -enable $newFileName swSameSetupButton;
  1028.         }
  1029.     }
  1030. }
  1031.  
  1032. proc createFileSelectionFrame(string $parent)
  1033. {
  1034.     setParent $parent;
  1035.  
  1036.     columnLayout swFileSelectionLayout;
  1037.     text
  1038.         -label "Image File Selection:";
  1039.     text
  1040.         -label "Click on the \"Browse\" button to select the image sequence.";
  1041.     textFieldButtonGrp
  1042.         -label "Sprite File"
  1043.         -annotation "Specify the file name of one of the images in the sequence."
  1044.         -text ""
  1045.         -buttonLabel "Browse"
  1046.         -buttonCommand "getSpriteBaseFile()"
  1047.         -changeCommand "updateSelectedFileInfo()"
  1048.         swFileSelectionGroup;
  1049.     textFieldGrp
  1050.         -label "Base Name"
  1051.         -text ""
  1052.         -annotation "This field will be filled automatically when a sprite file is specified."
  1053.         -editable false
  1054.         swSelectedFileText;
  1055.     columnLayout -visible false swFileRangeLayout;
  1056.     text -label "";
  1057.     text
  1058.         -label "Choose files within available continuous range that contains the selected file.";
  1059.     intFieldGrp
  1060.         -label "Min"
  1061.         -extraLabel "Max"
  1062.         -numberOfFields 2
  1063.         -value1 0
  1064.         -value2 0
  1065.         -enable false
  1066.         swFileRangeInt;
  1067.  
  1068.     updateSelectedFileInfo();
  1069. }
  1070.  
  1071. proc createAnimationFrame(string $parent)
  1072. // 
  1073. //    Description:
  1074. //        Create the Frame 1 UI.
  1075. //
  1076. //    Arguments:
  1077. //        The parent argument is assumed to be a tabLayout.
  1078.  
  1079. //
  1080. {
  1081.     setParent $parent;
  1082.  
  1083.     columnLayout swAnimationOptionsLayout;
  1084.     text
  1085.         -label "Image Assignment:";
  1086.  
  1087.     radioCollection
  1088.         swAnimationOptionCollection;
  1089.  
  1090.     radioButton
  1091.         -label "No animation. Use a single image for each particle."
  1092.         -ann "Each particle uses some fixed image throughout its lifetime"
  1093.         -sl
  1094.         -align "left"
  1095.         swSingleImageButton;
  1096.  
  1097.     radioButton
  1098.         -label "Cycle through the images for each particle."
  1099.         -ann "Each particle displays a sequence of images in turn"
  1100.         -align "left"
  1101.         swCycleButton;
  1102.  
  1103.     string $selectedFile =     `textFieldButtonGrp -q -fileName swFileSelectionGroup`;
  1104.     int $newFileName = newImageFileName($selectedFile);    
  1105.     radioButton
  1106.         -label "Use existing setup with new images."
  1107.         -ann "Use the new image sequence just picked and leave all other options unchanged. This option is only valid when editing existing particle sprites."
  1108.         -align "left"
  1109.         -cc "updateAnimationApplyButton()"
  1110.         -enable $newFileName
  1111.         swSameSetupButton;
  1112. }
  1113.  
  1114. global proc updateInvertRampCheckbox()
  1115. {
  1116.     int $useRamp = `radioButton -q -select swRampButton`;
  1117.     checkBox -e -enable $useRamp swInvertRampCheckbox;
  1118. }
  1119.  
  1120. proc createImageSelectionFrame(string $parent)
  1121. // 
  1122. //    Description:
  1123. //        Create the Frame 2 UI.
  1124. //
  1125. //    Arguments:
  1126. //        The parent argument is assumed to be a tabLayout.
  1127. //
  1128. {
  1129.     setParent $parent;
  1130.  
  1131.     columnLayout swImageSelectionLayout;
  1132.     text -label "Initial Sprite Assignment:";
  1133.     text
  1134.         -label "Select the technique used to assign the initial sprite to each particle:";
  1135.  
  1136.     radioCollection swImageSelectionOptionCollection;
  1137.     radioButton
  1138.         -label "Use the first image in the sequence"
  1139.         -ann "Every particle will use the first image in the sequence."
  1140.         -sl
  1141.         -align "left"
  1142.         swFirstImageButton;
  1143.     radioButton
  1144.         -label "Use each particle's \"particleId\" value"
  1145.         -ann "The particle will use its \"particleId\" to pick an image. If a particleId is greater than the number of images in the sequence, start over with the first."
  1146.         -align "left"
  1147.         swParticleIdButton;
  1148.     radioButton
  1149.         -label "Random"
  1150.         -ann "Each particle will choose a random image from the sequence."
  1151.         -align "left"
  1152.         swRandomButton;
  1153.     radioButton
  1154.         -label "Custom Start"
  1155.         -ann "The particle will use its \"spriteNumPP\" to pick an image.  It is the user's responsibility to set the spriteNumPP values by editing the particle creation expression."
  1156.         -align "left"
  1157.         swSpriteNumPPButton;
  1158.     radioButton
  1159.         -label "Use a ramp"
  1160.         -ann "A ramp will be connected to the \"spriteNumRamp\" attribute on the particle object.  This ramp can be modified to determine which sprite receives each image."
  1161.         -align "left"
  1162.         swInitRampButton;
  1163.  
  1164. }
  1165.  
  1166. global proc updateCycleLength()
  1167. {
  1168.     int $cycleOnce = `checkBox -q -value swCycleOnceCheckbox`;
  1169.     floatSliderGrp -e -enable (!$cycleOnce) swCycleLengthValue;
  1170. }
  1171.  
  1172. proc createCycleOptionsFrame(string $parent)
  1173. // 
  1174. //    Description:
  1175. //        Create the Frame 3 UI.
  1176. //
  1177. //    Arguments:
  1178. //        The parent argument is assumed to be a tabLayout.
  1179. //
  1180. {
  1181.     setParent $parent;
  1182.  
  1183.     columnLayout swCycleOptionsLayout;
  1184.     text -label "Animation Assignment:";
  1185.     text
  1186.         -label "How do you want the images to be cycled for each particle?";
  1187.  
  1188.     radioCollection swCycleOptionCollection;
  1189.     radioButton
  1190.         -label "Linearly Increasing"
  1191.         -ann "Play through the image sequence at an even speed."
  1192.         -sl
  1193.         -align "left"
  1194.         swLinearUpButton;
  1195.     radioButton
  1196.         -label "Ease-In/Ease-Out Increasing"
  1197.         -ann "Ease-in and ease-out the rate that the image sequence is played.  The first and last images in the sequence will be used for longer times."
  1198.         -align "left"
  1199.         swSmoothUpButton;
  1200.     radioButton
  1201.         -label "Linearly Increasing And Decreasing"
  1202.         -ann "Play through image sequence at an even speed. When the end of the sequence is reached, play it in reverse."
  1203.         -align "left"
  1204.         swLinearUpDownButton;
  1205.     radioButton
  1206.         -label "Ease-In/Ease-Out Increasing And Decreasing"
  1207.         -ann "Ease-in and ease-out the rate that the image sequence is played. When the end of the sequence is reached, play it in reverse."
  1208.         -align "left"
  1209.         swSmoothUpDownButton;
  1210.  
  1211.     radioButton
  1212.         -label "Use a ramp"
  1213.         -ann "A ramp will be connected to the \"spriteNumRamp\" attribute on the particle object.  This ramp can be modified to determine which sprite receives each image."
  1214.         -align "left"
  1215.         -cc "updateInvertRampCheckbox()"
  1216.         swRampButton;
  1217.  
  1218.     checkBox
  1219.         -label "Invert Ramp"
  1220.         -align "left"
  1221.         -value false
  1222.         -enable false
  1223.         -ann "Invert the meaning of the ramp's values.  Higher values mean use images closer to the start of the sequence."
  1224.         swInvertRampCheckbox;
  1225.  
  1226.     radioButton
  1227.         -label "Custom Cycling"
  1228.         -ann "The particle will use its \"spriteNumPP\" to pick an image.  It is the user's responsibility to set the spriteNumPP values by editing the particle runtime expression."
  1229.         -align "left"
  1230.         swSpriteCustomButton;
  1231.     
  1232.     separator -w 200 -h 5 -style "in";
  1233.  
  1234.     checkBox
  1235.         -label "Cycle only once during lifespan"
  1236.         -ann "The animation will be timed to cycle once during the particle lifespan."
  1237.         -align "left"
  1238.         -value true
  1239.         -changeCommand "updateCycleLength()"
  1240.         swCycleOnceCheckbox;
  1241.  
  1242.     floatSliderGrp
  1243.         -label "Cycle Length In Frames"
  1244.         -ann "This option is only valid if the \"Cycle only once during lifespan\" checkbox is disabled. It conrols the length of each animation cycle."
  1245.         -field true
  1246.         -min 1
  1247.         -precision 1
  1248.         -step 1.0
  1249.         -value 100.0
  1250.         -enable false
  1251.         swCycleLengthValue;
  1252.  
  1253.     checkBox
  1254.         -label "Invert Cycle"
  1255.         -align "left"
  1256.         -value false
  1257.         swInvertCycleCheckbox;
  1258.     
  1259. }
  1260.  
  1261. proc createSummaryFrame(string $parent)
  1262. // 
  1263. //    Description:
  1264. //        Create the Frame 3 UI.
  1265. //
  1266. //    Arguments:
  1267. //        The parent argument is assumed to be a tabLayout.
  1268. //
  1269. {
  1270.     setParent $parent;
  1271.  
  1272.     columnLayout swSummaryLayout;
  1273.     text
  1274.         -label "Summary";
  1275.     scrollField
  1276.         -width 442
  1277.         -height 150
  1278.         -editable false
  1279.         -font "smallPlainLabelFont"
  1280.         -text "This is a summary of the sprite options."
  1281.         swSummaryField; 
  1282. }
  1283.  
  1284. proc createTabs(string $parent)
  1285. // 
  1286. //    Description:
  1287. //
  1288. //    Arguments:
  1289. //        The parent argument is assumed to be a tabLayout.
  1290. //
  1291. {
  1292.     createGlobalsFrame($parent);
  1293.     createFileSelectionFrame($parent);
  1294.     createAnimationFrame($parent);
  1295.     createImageSelectionFrame($parent);
  1296.     createCycleOptionsFrame($parent);
  1297.     createSummaryFrame($parent);
  1298. }
  1299.  
  1300.  
  1301.  
  1302. proc createButtons(string $parent)
  1303. // 
  1304. //    Description:
  1305. //        Create buttons (one for each frame) that also switch between
  1306. //        the tabs.
  1307. //
  1308. //    Arguments:
  1309. //        The parent argument is assumed to be a formLayout.
  1310. //
  1311. {
  1312.     setParent $parent;
  1313.  
  1314.     string $frame1 = `button   -label "Continue"
  1315.                                     -ann "Make this choice, and go on to the next screen" 
  1316.                                     -command "swApplyContinueCallback"
  1317.                                              applyContinueButton`;
  1318.  
  1319.        string $frame2 = `button   -label "Back"
  1320.                                     -enable false
  1321.                                     -ann "Return to the previous screen" 
  1322.                                     -command "swBackCallback"
  1323.                                              backButton`;
  1324.  
  1325. //    string $frame3 = `button   -label "More Help" 
  1326. //                                    -ann "Explain some more about this topic"
  1327. //                                    -command "swMoreHelpCallback"
  1328. //                                             moreHelpButton`;
  1329.  
  1330.     string $frame4 = `button  -label "Close" 
  1331.                                     -ann "Quit the wizard and close the window"
  1332.                                     -command "swCloseCallback"
  1333.                                              closeButton`;
  1334.  
  1335.     formLayout -edit
  1336.         -attachForm     $frame1 "top"    5
  1337.         -attachForm     $frame1 "left"   5
  1338.         -attachForm     $frame1 "bottom" 5
  1339.         -attachPosition $frame1 "right"  2 33
  1340.  
  1341.         -attachForm     $frame2 "top"    5
  1342.         -attachPosition $frame2 "left"   2 33
  1343.         -attachPosition $frame2 "right"  2 66
  1344.         -attachForm     $frame2 "bottom" 5
  1345.  
  1346. //        -attachForm     $frame3 "top"    5
  1347. //        -attachPosition $frame3 "left"   2 50
  1348. //        -attachPosition $frame3 "right"  2 75
  1349. //        -attachForm     $frame3 "bottom" 5
  1350.  
  1351.         -attachForm     $frame4 "top"    5
  1352.         -attachPosition $frame4 "left"   2 66
  1353.         -attachForm     $frame4 "bottom" 5
  1354.         -attachForm     $frame4 "right"  5
  1355.  
  1356.         $parent;
  1357. }
  1358.  
  1359.  
  1360. global proc wizardWindow( string $particle, string $newImage )
  1361. // 
  1362. //    Description:
  1363. //
  1364. {
  1365.     global string $gSpriteWizardParticle;
  1366.     $gSpriteWizardParticle = $particle;
  1367.  
  1368.     //    If the window already exists then just show it and return.
  1369.     //
  1370.     if (`window -exists SpriteWizardWindow`) {
  1371.         deleteUI -window SpriteWizardWindow;
  1372.     }
  1373.  
  1374.     //    Otherwise, build the window.
  1375.     //
  1376.     window -title ("Sprite Wizard: "+$particle)
  1377.         -iconName "Sprite Wizard"
  1378.         -width    475
  1379.         -height   300
  1380.         -sizeable true
  1381.         WizardExampleWindow;
  1382.  
  1383.     string $menuBarLayout = `menuBarLayout`;
  1384.     menu -label "Edit";
  1385.         menuItem -label "Reset Settings" -c "resetSpriteSettings";
  1386.     menu -label "Help" -helpMenu true;
  1387.         menuItem -label "Help on the Sprite Wizard..." -c "showHelp SpriteWizard";
  1388.     setParent ..;
  1389.  
  1390.     string $form = `formLayout SpriteWizardForm`;
  1391.  
  1392.     string $tabs = `tabLayout -tabsVisible true
  1393.         -innerMarginWidth 5 -innerMarginHeight 5
  1394.         WizardExampleWindowTabs`;
  1395.     setParent ..;
  1396.  
  1397.     string $buttons = `formLayout`;
  1398.     setParent ..;
  1399.  
  1400.     createTabs($tabs);
  1401.     createButtons($buttons);
  1402.     wizardExampleWindowSelectFileSelection();
  1403.     
  1404.     tabLayout -edit
  1405.         -tabLabelIndex 1 "Globals"
  1406.         -tabLabelIndex 2 "Sprite File Selection"
  1407.         -tabLabelIndex 3 "Sprite Animation Options"
  1408.         -tabLabelIndex 4 "Image Selection Options"
  1409.         -tabLabelIndex 5 "Cycle Options"
  1410.         -tabLabelIndex 6 "Summary"
  1411.         $tabs;
  1412.         
  1413.     formLayout -edit
  1414.         -attachForm    $tabs    "top"    0
  1415.         -attachForm    $tabs    "left"   0
  1416.         -attachControl $tabs    "bottom" 0 $buttons
  1417.         -attachForm    $tabs    "right"  0
  1418.  
  1419.         -attachNone    $buttons "top"
  1420.         -attachForm    $buttons "left"   0
  1421.         -attachForm    $buttons "bottom" 0
  1422.         -attachForm    $buttons "right"  0
  1423.         $form;
  1424.  
  1425.     tabLayout -e -tabsVisible 0 WizardExampleWindowTabs;
  1426.  
  1427.     initializeWizardFromParticleShape( $particle, $newImage );
  1428.  
  1429.     showWindow WizardExampleWindow; 
  1430. }
  1431.  
  1432. global proc initializeWizardFromParticleShape( string $particle, string $newImage )
  1433. {
  1434.     if( $particle != "" )
  1435.     {
  1436.         string $particleChildren[] = `ls -dag -type particle $particle`;
  1437.         if( size( $particleChildren ) == 0 )
  1438.         {
  1439.             $particle = "";
  1440.         }
  1441.         else if( size( $particleChildren ) > 1 )
  1442.         {
  1443.             error("There are "+(size($particleChildren))+" particle objects at or below \""+$particle+"\" in the scene.  Select exactly one.");
  1444.         }
  1445.         else
  1446.         {
  1447.             $particle = $particleChildren[0];
  1448.         }
  1449.     }
  1450.  
  1451.     if( $particle == "" )
  1452.     {
  1453.         error("No particle object selected.  Select exactly one.");
  1454.     }
  1455.  
  1456.     textField -e -text $particle swGlobalParticleShape;
  1457.  
  1458.     if( $newImage == "" )
  1459.     {
  1460.         string $fileTexture = particleSpriteFileTexture( $particle );
  1461.         if( $fileTexture != "" )
  1462.         {
  1463.             string $file = `getAttr ($fileTexture+".fileTextureName")`;
  1464.             string $fileInfo[] = getConnectedFrameRange( $file );
  1465.             if( size( $fileInfo ) == 0 )
  1466.             {
  1467.                 $file = "";
  1468.             }
  1469.             textFieldButtonGrp -e -fileName $file swFileSelectionGroup;
  1470.             updateSelectedFileInfo();
  1471.  
  1472.             if( size( $fileInfo ) == 4 )
  1473.             {
  1474.                 int $startFrame =
  1475.                     `getAttr ($fileTexture+".startCycleExtension")`;
  1476.                 int $endFrame =
  1477.                     `getAttr ($fileTexture+".endCycleExtension")`;
  1478.                 intFieldGrp -e -value1 $startFrame swFileRangeInt;
  1479.                 intFieldGrp -e -value2 $endFrame swFileRangeInt;
  1480.             }
  1481.         }
  1482.     }
  1483.     else
  1484.     {
  1485.         textFieldButtonGrp -e -fileName $newImage swFileSelectionGroup;
  1486.         updateSelectedFileInfo();        
  1487.     }
  1488.  
  1489.     //
  1490.     // Animation
  1491.     //
  1492.     if( `attributeQuery -exists -node $particle SpriteAnimation` )
  1493.     {
  1494.         int $animation = `getAttr ($particle+".SpriteAnimation")`;
  1495.         switch( $animation )
  1496.         {
  1497.             case 0:
  1498.                 radioButton -e -select swSingleImageButton;
  1499.                 break;
  1500.                 case 1:
  1501.                 radioButton -e -select swCycleButton;
  1502.                 break;
  1503.         }
  1504.     }
  1505.     else
  1506.     {
  1507.         radioButton -e -select swSingleImageButton;
  1508.     }
  1509.  
  1510.     //
  1511.     // Image Selection
  1512.     //
  1513.     if( `attributeQuery -exists -node $particle SpriteStartOption` )
  1514.     {
  1515.         int $start = `getAttr ($particle+".SpriteStartOption")`;
  1516.         switch( $start )
  1517.         {
  1518.             case 0:
  1519.                 radioButton -e -select swFirstImageButton;
  1520.                 break;
  1521.             case 1:
  1522.                 radioButton -e -select swParticleIdButton;
  1523.                 break;
  1524.             case 2:
  1525.                 radioButton -e -select swRandomButton;
  1526.                 break;
  1527.             case 3:
  1528.                 radioButton -e -select swSpriteNumPPButton;
  1529.                 break;
  1530.             case 4:
  1531.                 radioButton -e -select swInitRampButton;
  1532.                 break;
  1533.         }
  1534.     }
  1535.     else
  1536.     {
  1537.         radioButton -e -select swFirstImageButton;
  1538.     }
  1539.     updateInvertRampCheckbox();
  1540.  
  1541.     //
  1542.     // Cycle Pattern
  1543.     //
  1544.     if( `attributeQuery -exists -node $particle SpriteCyclePattern` )
  1545.     {
  1546.         int $cycle = `getAttr ($particle+".SpriteCyclePattern")`;
  1547.         switch( $cycle )
  1548.         {
  1549.             case 0:
  1550.                 radioButton -e -select swLinearUpButton;
  1551.                 break;
  1552.             case 1:
  1553.                 radioButton -e -select swSmoothUpButton;
  1554.                 break;
  1555.             case 2:
  1556.                 radioButton -e -select swLinearUpDownButton;
  1557.                 break;
  1558.             case 3:
  1559.                 radioButton -e -select swSmoothUpDownButton;
  1560.                 break;
  1561.             case 4:
  1562.                 radioButton -e -select swSpriteCustomButton;
  1563.                 break;
  1564.             case 5:
  1565.                 radioButton -e -select swRampButton;
  1566.                 break;
  1567.         }
  1568.     }
  1569.     else
  1570.     {
  1571.         radioButton -e -select swLinearUpButton;
  1572.     }
  1573.  
  1574.     //
  1575.     // Cycle Length
  1576.     //
  1577.     if( `attributeQuery -exists -node $particle SpriteCycleLength` )
  1578.     {
  1579.         float $cycleLength =
  1580.             `getAttr ($particle+".SpriteCycleLength")`;
  1581.         floatSliderGrp -e -value $cycleLength swCycleLengthValue;
  1582.         if( $cycleLength == 0 )
  1583.         {
  1584.             checkBox -e -value 1 swCycleOnceCheckbox;
  1585.             floatSliderGrp -e -value 100.0 swCycleLengthValue;
  1586.         }
  1587.         else
  1588.         {
  1589.             checkBox -e -value 0 swCycleOnceCheckbox;
  1590.         }
  1591.     }
  1592.     else
  1593.     {
  1594.         checkBox -e -value 1 swCycleOnceCheckbox;
  1595.         floatSliderGrp -e -value 100.0 swCycleLengthValue;
  1596.     }
  1597.     updateCycleLength();
  1598.  
  1599.     //
  1600.     // Invert
  1601.     //
  1602.     if( `attributeQuery -exists -node $particle SpriteInvertCycle` )
  1603.     {
  1604.         int $invert = `getAttr ($particle+".SpriteInvertCycle")`;
  1605.         checkBox -e -value $invert swInvertRampCheckbox;
  1606.         checkBox -e -value $invert swInvertCycleCheckbox;
  1607.     }
  1608.     else
  1609.     {
  1610.         checkBox -e -value 0 swInvertRampCheckbox;
  1611.         checkBox -e -value 0 swInvertCycleCheckbox;
  1612.     }
  1613. }
  1614.  
  1615. global proc string particleSpriteFileTexture( string $particle )
  1616. {
  1617.     string $result = "";
  1618.     if( size( `ls -type particle $particle` ) == 1 )
  1619.     {
  1620.         if( `getAttr ($particle+".particleRenderType")` == 5 )
  1621.         {
  1622.             string $shadingGroups[] =
  1623.                 `listConnections -source false -destination true
  1624.                 -plugs false ($particle+".instObjGroups")`;
  1625.             int $i;
  1626.             for( $i = 0; $i < size( $shadingGroups ); $i ++ )
  1627.             {
  1628.                 string $shaders[] =
  1629.                     `listConnections -source true
  1630.                     -destination false -plugs false
  1631.                     ($shadingGroups[$i]+".surfaceShader")`;
  1632.                 $shaders = `ls -type lambert $shaders`;
  1633.                 int $j;
  1634.                 for( $j = 0; $j < size( $shaders ); $j ++ )
  1635.                 {
  1636.                     string $drivingColor[] =
  1637.                         `listConnections -plugs false
  1638.                         -source true -destination false
  1639.                         ($shaders[$j]+".color")`;
  1640.                     if( size( $drivingColor ) > 0 )
  1641.                     {
  1642.                         string $fileTx[] = `ls -type file $drivingColor[0]`;
  1643.                         if( size( $fileTx ) > 0 )
  1644.                         {
  1645.                             $result = $fileTx[0];
  1646.                             return $result;
  1647.                         }
  1648.                     }
  1649.                 }
  1650.             }
  1651.         }
  1652.     }
  1653.  
  1654.     return $result;
  1655. }
  1656.  
  1657. global proc string[] getConnectedFrameRange( string $fileName )
  1658. {
  1659.     string $result[];
  1660.     clear( $result );
  1661.  
  1662.     //
  1663.     // First, make sure that the given string.
  1664.     // is a readable file.
  1665.     //
  1666.     if( `filetest -r $fileName` == 0 )
  1667.     {
  1668.         print("// Error: Cannot read file: "+$fileName+"\n");
  1669.         return $result;
  1670.     }
  1671.  
  1672.     //
  1673.     // Now get the path to the file.
  1674.     //
  1675.     string $path[];
  1676.     clear( $path );
  1677.     tokenize( $fileName, "/", $path );
  1678.     int $pathCount = size( $path );
  1679.  
  1680.     string $pathDir = "";
  1681.     if( substring( $fileName, 1, 1 ) == "/" )
  1682.     {
  1683.         $pathDir = "/";
  1684.     }
  1685.     string $fileBase = $path[$pathCount-1];
  1686.     int $j;
  1687.     for( $j = 0; $j < ( $pathCount - 1 ); $j ++ )
  1688.     {
  1689.         $pathDir = ( $pathDir + $path[$j] + "/" );
  1690.     }
  1691.  
  1692.     //
  1693.     // Now try to find which part of the file's name contains
  1694.     // the extensions.
  1695.     //
  1696.     string $parts[];
  1697.     clear( $parts );
  1698.     tokenize( $fileBase, ".", $parts );
  1699.     int $partCount = size( $parts );
  1700.     int $numberPart[];
  1701.     int $isFileNumbered = 0;
  1702.     int $extension = 0;
  1703.     for( $j = 0; $j < $partCount; $j ++ )
  1704.     {
  1705.         if( `gmatch $parts[$j] "[0-9]*"` == 1 )
  1706.         {
  1707.             $numberPart[$j] = 1;
  1708.             $isFileNumbered = 1;
  1709.             $extension = $j;
  1710.         }
  1711.         else
  1712.         {
  1713.             $numberPart[$j] = 0;
  1714.         }
  1715.     }
  1716.  
  1717.     if( $isFileNumbered == 0 )
  1718.     {
  1719.         clear( $result );
  1720.         $result[0] = $pathDir;
  1721.         $result[1] = $fileBase;
  1722.         return $result;
  1723.     }
  1724.  
  1725.     int $selectedImageNumber = $parts[$extension];
  1726.  
  1727.     int $fileIsPadded = 0;
  1728.     if( size( $parts[$extension] ) > 1 )
  1729.     {
  1730.         if( substring( $parts[$extension], 1, 1 ) == "0" )
  1731.         {
  1732.             //
  1733.             // Since the numbering is more than 1 character long,
  1734.             // and the first character is "0", we assume that
  1735.             // the file numbering is using padding.
  1736.             //
  1737.             $fileIsPadded = 1;
  1738.         }
  1739.     }
  1740.  
  1741.     string $format = "";
  1742.     for( $j = 0; $j < $partCount; $j ++ )
  1743.     {
  1744.         if( $j == $extension )
  1745.         {
  1746.             if( $fileIsPadded == 1 )
  1747.             {
  1748.                 $format += "????";
  1749.             }    
  1750.             else
  1751.             {
  1752.                 $format += "*";
  1753.             }
  1754.         }
  1755.         else
  1756.         {
  1757.             $format += $parts[$j];
  1758.         }
  1759.  
  1760.         if( $j < ( $partCount - 1 ) )
  1761.         {
  1762.             $format += ".";
  1763.         }
  1764.     }
  1765.  
  1766.     string $candidateFiles[];
  1767.     clear( $candidateFiles );
  1768.     if( $pathDir != "" )
  1769.     {
  1770.         $candidateFiles =
  1771.             `getFileList -folder $pathDir -filespec $format`;
  1772.     }
  1773.     else
  1774.     {
  1775.         $candidateFiles =
  1776.             `getFileList -filespec $format`;
  1777.     }
  1778.     int $fileCount = size( $candidateFiles );
  1779.     if( $fileCount == 1 )
  1780.     {
  1781.         clear( $result );
  1782.         if( $fileBase == $candidateFiles[0] )
  1783.         {
  1784.             $result[0] = $pathDir;
  1785.             $result[1] = $fileBase;
  1786.         }
  1787.         else
  1788.         {
  1789.             //
  1790.             // If the one matching file is not the
  1791.             // selected file, then something is
  1792.             // really messed up.
  1793.             //
  1794.         }
  1795.         return $result;
  1796.     }
  1797.  
  1798.     //
  1799.     // Loop over all of the files that match the format to
  1800.     // find ones that are within the continuous range that
  1801.     // includes the selected file.
  1802.     //
  1803.     int $numbers[];
  1804.     clear( $numbers );
  1805.     for( $j = 0; $j < size( $candidateFiles ); $j ++ )
  1806.     {
  1807.         string $candidateParts[];
  1808.         tokenize( $candidateFiles[$j], ".", $candidateParts );
  1809.         string $ext = $candidateParts[$extension];
  1810.         int $padded = 0;
  1811.         if( size( $ext ) > 1 )
  1812.         {
  1813.             if( substring( $ext, 1, 1 ) == "0" )
  1814.             {
  1815.                 $padded = 1;
  1816.             }
  1817.         }
  1818.  
  1819.         //
  1820.         // Only keep the files that seem to match the
  1821.         // format.
  1822.         //
  1823.         if( $fileIsPadded == $padded )
  1824.         {
  1825.             $numbers[size( $numbers )] = $ext;
  1826.         }
  1827.     }
  1828.     $numbers = sort( $numbers );
  1829.  
  1830.     int $selectedLocation = -1;
  1831.     for( $j = 0; $j < size( $numbers ); $j ++ )
  1832.     {
  1833.         if( $numbers[$j] == $selectedImageNumber )
  1834.         {
  1835.             $selectedLocation = $j;
  1836.             break;
  1837.         }
  1838.     }
  1839.  
  1840.     if( $selectedLocation == -1 )
  1841.     {
  1842.         //
  1843.         // The selected file was not in the matching list.
  1844.         // That means that something got really messed up.
  1845.         //
  1846.         clear( $result );
  1847.         return $result;
  1848.     }
  1849.  
  1850.     //
  1851.     // Starting at the location of the selected image, work
  1852.     // up and down the $numbers array to find the maximum range
  1853.     // of continuous numbers.
  1854.     //
  1855.     int $minimumIndex = -1;
  1856.     if( $selectedLocation == 0 )
  1857.     {
  1858.         $minimumIndex = 0;
  1859.     }
  1860.     int $maximumIndex = -1;
  1861.     if( $selectedLocation == ( size( $numbers ) - 1 ) )
  1862.     {
  1863.         $maximumIndex = $selectedLocation;
  1864.     }
  1865.  
  1866.     if( $minimumIndex == -1 )
  1867.     {
  1868.         int $lastValue = $numbers[$selectedLocation];
  1869.         for( $j = $selectedLocation - 1; $j >= 0; $j -- )
  1870.         {
  1871.             if( ( $lastValue - $numbers[$j] ) > 1 )
  1872.             {
  1873.                 break;
  1874.             }
  1875.             $lastValue = $numbers[$j];
  1876.             $minimumIndex = $j;
  1877.         }
  1878.     }
  1879.     if( $minimumIndex == -1 )
  1880.     {
  1881.         $minimumIndex = $selectedLocation;
  1882.     }
  1883.  
  1884.     if( $maximumIndex == -1 )
  1885.     {
  1886.         int $lastValue = $numbers[$selectedLocation];
  1887.         for( $j = $selectedLocation + 1; $j < size( $numbers ); $j ++ )
  1888.         {
  1889.             if( ( $numbers[$j] - $lastValue ) > 1 )
  1890.             {
  1891.                 break;
  1892.             }
  1893.             $lastValue = $numbers[$j];
  1894.             $maximumIndex = $j;
  1895.         }
  1896.     }
  1897.     if( $maximumIndex == -1 )
  1898.     {
  1899.         $maximumIndex = $selectedLocation;
  1900.     }
  1901.  
  1902.     $result[0] = $pathDir;
  1903.     $result[1] = $fileBase;
  1904.  
  1905.     if( $numbers[$maximumIndex] != $numbers[$minimumIndex] )
  1906.     {
  1907.         $result[2] = $numbers[$minimumIndex];
  1908.         $result[3] = $numbers[$maximumIndex];
  1909.     }
  1910.  
  1911.     return $result;
  1912. }
  1913.  
  1914.